<template>
	<view>
		<view class="detail">
			<view class="title">{{objdata.title}}</view>
			<view class="content">{{objdata.body}}</view>
		</view>
		<view class="comment" >
			<view class="text">评论</view>
			<view class="row" v-for="item in Comments" :key="item.id">
				<view class="top">
					<view class="name">{{item.name}}</view>
					<view class="mail">{{item.email}}</view>
				</view>
				<view class="body">
					{{item.body}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				objdata:{},
				id:1,
				Comments:[]
			};
		},
		methods:{
			getdetail(){
				uni.showLoading({
					title:"数据加载中...",
					mask:true
				}),
				uni.request({
					url:"http://jsonplaceholder.typicode.com/posts/"+this.id,
					success: (res) => {
						console.log(res);
						this.objdata=res.data
					},
					complete:()=>{
						uni.hideLoading()
					}
				})
			},
			getcomments(){
				uni.request({
					url:`http://jsonplaceholder.typicode.com/posts/${this.id}/comments`,
					success: (res) => {
						this.Comments=res.data
					}
				})
			}
		},
		onLoad(e){
			this.id=e.id
			this.getdetail();
			this.getcomments();
		}
	}
</script>

<style lang="scss">
	.detail{
		padding: 30rpx;
		.title{
			font-size: 46rpx;
			color: #000;
			padding-bottom: 20rpx;
		}
		.content{
			font-size: 30rpx;
			color: #666;
			padding-bottom: 60rpx;
		}
	}
	.comment{
		padding: 30rpx;
		background: #f8f8f8;
		.text{
			font-size: 46rpx;
			margin-bottom: 30rpx;
		}
		.row{
			border-bottom: 1px solid #e8e8e8;
			padding: 20rpx 0;
			.top{
				display: flex;
				justify-content: space-between;
				font-size: 22rpx;
				color: #999;
				padding-bottom: 15rpx;
			}
			.body{
				font-size: 28rpx;
				color: #555;
			}
		}
	}
</style>
